package action;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JTable;
import modeles.Contact;
import controller.ControllerTab;
import vues.EditContactWindow;
import vues.HomeWindow;
import vues.MainWindow;

/**
 * Class Action Edition de contact
 * window		Objet MainWindow
 * homeView		Objet HomeWindow
 * tableau		Objet JTable 
 * modele		Objet ControllerTab
 * 
 * @author Paul BEZARD-FALGAS
 */
public class ActionEditContact extends AbstractAction{

		private static final long serialVersionUID = 1L;
		private HomeWindow homeView;
		private MainWindow window;
		private JTable tableau;
		private ControllerTab modele;

		public ActionEditContact(HomeWindow homeWindow, MainWindow wind){
			super("Edit Contact");
			this.window = wind;
			this.tableau = this.window.getTableau();
			this.modele = this.window.getModele();
			this.homeView = homeWindow;
		}	  
		
		public void actionPerformed(ActionEvent e){
			//get rows contact of table
			int[] selection = tableau.getSelectedRows();
			int id = selection[0];
			
			//Keep in memory contact to edit
			Contact contact = this.modele.get(selection[0]);
			 
            //view edit
            new EditContactWindow(homeView, contact, modele, id);
		}

}
